BI.TreeNodeSwitcher = BI.inherit(BI.NodeButton, {
    _defaultConfig: function () {
        return BI.extend(BI.TreeNodeSwitcher.superclass._defaultConfig.apply(this, arguments), {
            baseCls: "bi-tree-node-switcher",
            iconWidth: 24,
            iconHeight: 24,
            isFirstNode: false,
            isLastNode: false,
            layer: 0
        });
    },

    render: function () {

        const [collapse, expand] = this.getIconCls();

        return {
            type: "bi.icon_label",
            iconWidth: this.options.iconWidth,
            iconHeight: this.options.iconHeight,
            cls: this.options.open ? expand : collapse,
        };
    },

    getIconCls: function () {
        var options = this.options;
        if (options.layer === 0 && options.isFirstNode && options.isLastNode) {
            //  只有一层，并且是第一个节点，并且是最后一个节点
            return BI.STYLE_CONSTANTS.LINK_LINE_TYPE === "solid" ? ["tree-solid-collapse-icon-type1", "tree-solid-expand-icon-type1"] : ["tree-collapse-icon-type1", "tree-expand-icon-type1"];
        } else if (options.layer === 0 && options.isFirstNode) {
            //  第一层，并且是第一个节点
            return BI.STYLE_CONSTANTS.LINK_LINE_TYPE === "solid" ? ["tree-solid-collapse-icon-type2", "tree-solid-expand-icon-type2"] : ["tree-collapse-icon-type2", "tree-expand-icon-type2"];
        } else if (options.isLastNode) {
            //  最后一个节点
            return BI.STYLE_CONSTANTS.LINK_LINE_TYPE === "solid" ? ["tree-solid-collapse-icon-type4", "tree-solid-expand-icon-type4"] : ["tree-collapse-icon-type4", "tree-expand-icon-type4"];
        } else {
            //  其他情况
            return BI.STYLE_CONSTANTS.LINK_LINE_TYPE === "solid" ? ["tree-solid-collapse-icon-type3", "tree-solid-expand-icon-type3"] : ["tree-collapse-icon-type3", "tree-expand-icon-type3"];
        }
    },

    setOpened: function (b) {
        BI.TreeNodeSwitcher.superclass.setOpened.apply(this, arguments);
        const [collapse, expand] = this.getIconCls();
        if (b) {
            this.element.addClass(expand).removeClass(collapse);
        } else {
            this.element.addClass(collapse).removeClass(expand);
        }
    },

    doClick: function () {
        BI.TreeNodeSwitcher.superclass.doClick.apply(this, arguments);
        this.fireEvent(BI.TreeNodeSwitcher.EVENT_CHANGE, this);
    }
});

BI.TreeNodeSwitcher.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.tree_node_switcher", BI.TreeNodeSwitcher);
